/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.bid.service.plugins  
 */
package com.apache.bid.service.plugins;

import org.apache.log4j.Logger;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.bid.common.cache.BidCacheFactory;
import com.apache.bid.common.cache.BidCacheManager;
import com.apache.bid.entity.BidApply;
import com.apache.bid.entity.BidMaxContent;
import com.apache.bid.manager.BidApplyManager;
import com.apache.bid.manager.BidItemGroupManager;
import com.apache.bid.manager.BidItemManager;
import com.apache.bid.manager.BidMaxContentManager;
import com.apache.bid.manager.BidPubManager;
import com.apache.bid.manager.BidSessionManager;
import com.apache.cache.util.Validator;

/**
 * description:  统一下删除活动插件
 * @author Hou Dayu 创建时间：2016-3-23  
 * 
 */
public class UnityDelSessionPluginImpl implements PluginConnector {

	protected Logger log = Logger.getLogger(getClass());
	protected BidSessionManager bidSessionManager;
	protected BidPubManager bidPubManager;
	protected BidItemGroupManager bidItemGroupManager;
	protected BidApplyManager bidApplyManager;
	protected BidMaxContentManager bidMaxContentManager;
	protected BidItemManager bidItemManager;

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.zbxsoft.api.manager.PluginConnector#execute(com.zbxsoft.api.vo.ParamsVo)  
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Object execute(ParamsVo param) throws Exception {
		ResultEntity entity = new ResultEntity();
		String sessionId = Validator.getDefaultStr(param.getInfoId(), String.valueOf(param.getParams("infoId")));
		if (Validator.isNull(sessionId)) {
			entity.setResult("false");
			entity.setMessage("缺少必要参数，程序执行失败");
			return entity;
		}
		ParamsVo vo = new ParamsVo();
		vo.setInfoId(sessionId);
		boolean mark = bidSessionManager.deleteInfo(vo);
		if (mark) {
			ParamsVo pvo = new ParamsVo();
			pvo.setParams("sessionId", sessionId);
			bidPubManager.deleteInfo(pvo);
			bidItemManager.deleteInfo(pvo);
			bidItemGroupManager.deleteInfo(pvo);
			BidMaxContent mct = new BidMaxContent();
			mct.setObjId(sessionId);
			mct.setObjType("sessions");
			pvo.setObj(mct);
			bidMaxContentManager.deleteInfo(pvo);
			BidApply bidApply = new BidApply();
			bidApply.setSessionId(sessionId);
			pvo.setObj(bidApply);
			bidApplyManager.deleteInfo(pvo);
			BidCacheManager cache = BidCacheFactory.getInstance().getCacheManager("session");
			cache.removeCacheObject(BidCacheManager.session_prefix + sessionId);
		}
		entity.setEntity(mark);
		entity.setResult("true");
		entity.setMessage("session删除成功");
		return entity;
	}

	public void setBidSessionManager(BidSessionManager bidSessionManager) {
		this.bidSessionManager = bidSessionManager;
	}

	public void setBidPubManager(BidPubManager bidPubManager) {
		this.bidPubManager = bidPubManager;
	}

	public void setBidItemGroupManager(BidItemGroupManager bidItemGroupManager) {
		this.bidItemGroupManager = bidItemGroupManager;
	}

	public void setBidApplyManager(BidApplyManager bidApplyManager) {
		this.bidApplyManager = bidApplyManager;
	}

	public void setBidMaxContentManager(BidMaxContentManager bidMaxContentManager) {
		this.bidMaxContentManager = bidMaxContentManager;
	}

	public void setBidItemManager(BidItemManager bidItemManager) {
		this.bidItemManager = bidItemManager;
	}

}
